﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Web.UI;

using System.IO;
using System.Web.UI.HtmlControls;
using TA.Win.Utils.Design;
using System.Drawing.Design;
using System.Web.UI.Design;

namespace TA.Turbo.Controls
{
	/// <summary>
	/// Describes one tab panel in a tab container control.
	/// </summary>
	[Designer(typeof(ContainerControlDesigner))]
	public class TabPanel : BaseComplexControl
	{
		#region PUBLIC
		#region INIT
		/// <summary>
		/// Ctor.
		/// </summary>
		public TabPanel()
		{
			Tag = HtmlTextWriterTag.Div;
		}
		#endregion
		#region PROPS
		/// <summary>
		/// Controls the appearance of the tab's header.
		/// </summary>
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
		[Editor(typeof(PropertyEditor), typeof(UITypeEditor))]
		public StyledLabelElement Header { get { return _header; } }
		/// <summary>
		/// If false, tab is not visible and can't be selected.
		/// </summary>
		public override bool Enabled
		{
			get
			{
				return base.Enabled;
			}
			set
			{
				base.Enabled = value;
				this._spanTab.Style[HtmlTextWriterStyle.Display] = value ? "inline-block" : "none";
				if (!value && this._container != null)
					this._container.VerifyActiveTab();
			}
		}
		[Browsable(false)]
		public TabContainer Container
		{
			get
			{
				return this.Parent.Parent as TabContainer;
			}
		}
		#endregion
		#endregion
		#region INTERNAL
		#region VARS
		StyledLabelElement _header = new StyledLabelElement();
		internal HtmlGenericControl _spanTab = new HtmlGenericControl("SPAN");
		internal TabContainer _container;
		#endregion
		protected override void AddAttributesToRender(HtmlTextWriter writer)
		{
			if (this.Container.Height != null)
				writer.AddStyleAttribute(HtmlTextWriterStyle.Height, this.Container.Height + "px");

			base.AddAttributesToRender(writer);
		}
		#endregion
	}
}